const WXAPI = require('apifm-wxapi')
const AUTH = require('../../utils/auth')
const CONFIG = require("../../config")
const config = require('../../config')
const APP = getApp()

APP.configLoadOK = () => {

}
Page({
  data: {
    list: '',
  },
  houduanButton1: function () {
    var that = this;
    wx.request({
      url: 'http://'+config.ip+':'+config.port+'/queue/list',
      data:{
        phone:15080077937,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)//打印到控制台
        var list = res.data;
        if (list == null) {
          var toastText = '数据获取失败';
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            list: list,
          })
        }
      }
    })
  },
  houduanButton2: function () {
    var that = this;
    wx.request({
      url: 'http://'+config.ip+':'+config.port+'/queue/total',
      method: 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)//打印到控制台
        var totallist = res.data;
        if (totallist == null) {
          var toastText = '数据获取失败';
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        } else {
          that.setData({
            totallist: totallist,
          })
        }
      }
    })
  },
  queuingGet: function (e) {
    console.log(e.currentTarget.id);
    var that = this;
    wx.request({
      url: 'http://'+config.ip+':'+config.port+'/queue/add',
      data:{
        phone:15080077937,
        type:e.currentTarget.id,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data)//打印到控制台
        
        var msg = res.data;
        if (msg == 'no') {
          var toastText = '无需重复取号，您有一个取号正在等待处理中...';
          wx.showToast({
            title: toastText,
            icon: 'none',
            duration: 2000
          });
        } else {
          var toastText = '取号成功！';
          wx.showToast({
            title: toastText,
            icon: '',
            duration: 2000
          });
        }
        that.onShow();
      }
    })
  },
 
  onLoad: function (options) {
  },
  onShow: function () {
    this.houduanButton1();
    this.houduanButton2();
  },
  processLogin(e) {
    if (!e.detail.userInfo) {
      wx.showToast({
        title: '已取消',
        icon: 'none',
      })
      return;
    }
    AUTH.register(this);
  },

 
})